package com.hy.controller;

import com.hy.bean.*;
import com.hy.service.EmployeetableService;
import com.hy.vo.EmpDeptVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Employeetable)表控制层
 *
 * @author makejava
 * @since 2024-05-14 22:00:29
 */
@CrossOrigin
@RestController
@RequestMapping("employeetable")
public class EmployeetableController {
    /**
     * 服务对象
     */
    @Resource
    private EmployeetableService employeetableService;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/listPage")
    public PageResult<EmpDeptVo> queryByPage(@RequestParam(defaultValue = "1") Integer currPage, @RequestParam(defaultValue = "5") Integer pageSize, Employeetable employeetable){
        logger.debug("分页查询===>currPage{},====>pageSize{}", currPage, pageSize);
        logger.debug("分页查询条件===>Employeetable2====>{}", employeetable);
        return employeetableService.list(currPage, pageSize, employeetable);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/getById/{id}")
    public Employeetable queryById(@PathVariable("id") Integer id) {
        return null;
    }

    @GetMapping("/getByEmployeeNumber/{employeeNumber}")
    public RespBean queryByEmployeeNumber(@PathVariable("employeeNumber") String employeeNumber){
        return employeetableService.getEmpDeptVo(employeeNumber);
    }

    /**
     * 新增数据
     *
     * @param employeetable 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public RespBean add(@RequestBody Employeetable employeetable) {
        return employeetableService.save(employeetable);
    }

    /**
     * 编辑数据
     *
     * @param employeetable 实体
     * @return 编辑结果
     */
    @PutMapping("/update")
    public RespBean edit(@RequestBody Employeetable employeetable) {
        logger.debug("编辑数据===>employeetable====>{}", employeetable);
        return employeetableService.updateByid(employeetable);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public RespBean deleteById(@PathVariable("id") Integer id) {
        return employeetableService.deletById(id);
    }
}

